/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rbh.risk.entity;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Cacheable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

/**
 *
 * @author M
 */
@Entity
@Table(name = "rbh_risk_workgroup")
@Cacheable
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
@XmlRootElement
public class Workgroup implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "WORKGROUP_ID", unique = true, nullable = false, columnDefinition = "mediumint UNSIGNED")
    private Integer workgroupId;
    @Basic(optional = false)
    @Column(name = "WORKGROUP_NAME", length = 100, nullable = false)
    private String workgroupName;
    @Column(name = "WORKGROUP_ABBREVIATION", length = 5)
    private String workgroupAbbreviation;
    @Basic(optional = false)
    @Column(name = "WORKGROUP_STATUS", columnDefinition = "boolean default true", nullable = false)
    private boolean workgroupStatus;
    @Basic(optional = false)
    @Column(name = "WORKGROUP_ORDER_NUMBER", columnDefinition = "tinyint UNSIGNED default 0", nullable = false)
    private short workgroupOrderNumber;
    @Column(name = "WORKGROUP_DESCRIPTION", length = 1024)
    private String workgroupDescription;
    @JoinColumn(name = "RBH_RISK_WORKGROUP_LEVEL", referencedColumnName = "WORKGROUP_LEVEL_ID")
    @ManyToOne(fetch = FetchType.LAZY)
    private WorkgroupLevel workgroupLevel;
    @JoinColumn(name = "RBH_RISK_WORKGROUP", referencedColumnName = "WORKGROUP_ID")
    @ManyToOne(fetch = FetchType.LAZY)
    private Workgroup workgroup;
    @OneToMany(mappedBy = "workgroup", fetch = FetchType.LAZY)
    @Cascade({CascadeType.DETACH})
    private List<Workgroup> workgroupList;
    @ManyToMany(mappedBy = "workgroupList", fetch = FetchType.LAZY)
    @Cascade({CascadeType.DETACH})
    private List<Profile> profileList;

    public Workgroup() {
    }

    public Workgroup(Integer workgroupId) {
        this.workgroupId = workgroupId;
    }

    public Workgroup(Integer workgroupId, String workgroupName) {
        this.workgroupId = workgroupId;
        this.workgroupName = workgroupName;
    }

    public Integer getWorkgroupId() {
        return workgroupId;
    }

    public void setWorkgroupId(Integer workgroupId) {
        this.workgroupId = workgroupId;
    }

    public String getWorkgroupName() {
        return workgroupName;
    }

    public void setWorkgroupName(String workgroupName) {
        this.workgroupName = workgroupName;
    }

    public String getWorkgroupAbbreviation() {
        return workgroupAbbreviation;
    }

    public void setWorkgroupAbbreviation(String workgroupAbbreviation) {
        this.workgroupAbbreviation = workgroupAbbreviation;
    }

    public WorkgroupLevel getWorkgroupLevel() {
        return workgroupLevel;
    }

    public void setWorkgroupLevel(WorkgroupLevel workgroupLevel) {
        this.workgroupLevel = workgroupLevel;
    }

    public boolean isWorkgroupStatus() {
        return workgroupStatus;
    }

    public void setWorkgroupStatus(boolean workgroupStatus) {
        this.workgroupStatus = workgroupStatus;
    }

    public short getWorkgroupOrderNumber() {
        return workgroupOrderNumber;
    }

    public void setWorkgroupOrderNumber(short workgroupOrderNumber) {
        this.workgroupOrderNumber = workgroupOrderNumber;
    }

    public String getWorkgroupDescription() {
        return workgroupDescription;
    }

    public void setWorkgroupDescription(String workgroupDescription) {
        this.workgroupDescription = workgroupDescription;
    }

    public Workgroup getWorkgroup() {
        return workgroup;
    }

    public void setWorkgroup(Workgroup workgroup) {
        this.workgroup = workgroup;
    }

    public List<Workgroup> getWorkgroupList() {
        return workgroupList;
    }

    public void setWorkgroupList(List<Workgroup> workgroupList) {
        this.workgroupList = workgroupList;
    }

    public List<Profile> getProfileList() {
        return profileList;
    }

    public void setProfileList(List<Profile> profileList) {
        this.profileList = profileList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (workgroupId != null ? workgroupId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Workgroup)) {
            return false;
        }
        Workgroup other = (Workgroup) object;
        if ((this.workgroupId == null && other.workgroupId != null) || (this.workgroupId != null && !this.workgroupId.equals(other.workgroupId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.rbh.risk.entity.Workgroup[ workgroupId=" + workgroupId + " ]";
    }
}